#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

//void Swap(string& s, int left, int right)
//{
//    while (left < right)
//    {
//        char k = s[left];
//        s[left] = s[right];
//        s[right] = k;
//        left++;
//        right--;
//    }
//}
//
//int main() {
//    string str;
//    getline(cin, str);
//    int n = str.size();
//    int left = 0;
//    int right = 0;
//    while (right <= n)
//    {
//        if (right + 1 <= n && (right + 1 == n || str[right + 1] == ' '))
//        {
//            Swap(str, left, right);
//            left = right + 2;
//        }
//        right++;
//    }
//    Swap(str, 0, n - 1);
//    cout << str << endl;
//    return 0;
//}


int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    int max_size = max(min(n / 2, m) * a, min(n, m / 2) * b);
    cout << max_size << endl;
    return 0;
}

int main() {
    long long n, m, a, b;
    cin >> n >> m >> a >> b;
    long long max_a = min(n / 2, m);
    long long max_b = min(n, m / 2);
    long long max_aa = max_a * a + min(n - 2 * max_a, m - max_a) * b;
    long long max_bb = max_b * b + min(n - max_b, m - 2 * max_b) * a;
    cout << max(max_aa, max_bb) << endl;
    return 0;
}

int main() {
    long long n, m, a, b;
    cin >> n >> m >> a >> b;
    long long ret = 0;
    for (long long x = 0; x <= min(n / 2, m); x++)
    {
        long long y = min(n - x * 2, (m - x) / 2);
        ret = max(x * a + y * b, ret);
    }
    cout << ret << endl;
    return 0;
}

int main() {
    int n;
    cin >> n;
    vector<int> ret(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ret[i];
    }
    int pre = 0;
    for (int i = 1; i < n; i++)
    {
        if (ret[i - 1] < ret[i])
        {
            pre += ret[i] - ret[i - 1];
        }
    }
    cout << pre << endl;
    return 0;
}

int main() {
    string str1;
    string str2;
    getline(cin, str1);
    getline(cin, str2);
    unordered_map<char, int> hash;
    for (auto s : str2)
    {
        hash[s]++;
    }
    string str3;
    for (auto s : str1)
    {
        if (hash[s] == 0)
        {
            str3 += s;
        }
    }
    swap(str1, str3);
    cout << str1 << endl;
    return 0;
}

int main() {
    string str1;
    string str2;
    getline(cin, str1);
    getline(cin, str2);
    unordered_map<char, int> hash;
    for (auto s : str2)
    {
        hash[s]++;
    }
    string str3;
    for (auto s : str1)
    {
        if (hash[s] == 0)
        {
            str3 += s;
        }
    }
    swap(str1, str3);
    cout << str1 << endl;
    return 0;
}

struct ListNode 
{
    int val;
 	struct ListNode *next;
};


struct ListNode* FindFirstCommonNode(struct ListNode* pHead1, struct ListNode* pHead2) {
    // write code here
    if (pHead1 == NULL || pHead2 == NULL)
    {
        return NULL;
    }
    struct ListNode* p1 = pHead1;
    struct ListNode* p2 = pHead2;
    int x = 0, y = 0;
    while (p1->next)
    {
        p1 = p1->next;
        x++;
    }
    while (p2->next)
    {
        p2 = p2->next;
        y++;
    }
    if (p1 == p2)
    {
        p1 = pHead1;
        p2 = pHead2;
        if (x > y)
        {
            int z = x - y;
            while (z)
            {
                p1 = p1->next;
                z--;
            }
            while (p1 != p2)
            {
                p1 = p1->next;
                p2 = p2->next;
            }
            return p1;
        }
        else
        {
            int z = y - x;
            while (z)
            {
                p2 = p2->next;
                z--;
            }
            while (p1 != p2)
            {
                p1 = p1->next;
                p2 = p2->next;
            }
            return p1;
        }
    }
    return NULL;
}

int main() {
    int n;
    cin >> n;
    string str;
    cin >> str;
    vector<int> p1(n);
    vector<int> p2(n);
    vector<long long> p3(n);
    if (str[0] == 's')
    {
        p1[0] = 1;
    }
    for (int i = 1; i < n; i++)
    {
        p1[i] = p1[i - 1] + (str[i] == 's' ? 1 : 0);
        p2[i] = p2[i - 1] + (str[i] == 'h' ? 1 : 0) * p1[i - 1];
        p3[i] = p3[i - 1] + (str[i] == 'y' ? 1 : 0) * p2[i - 1];
    }
    cout << p3[n - 1] << endl;
    return 0;
}

int main() {
    int n;
    cin >> n;
    string str;
    cin >> str;
    int s = 0;
    long long h = 0;
    long long y = 0;
    for (auto p : str)
    {
        if (p == 's')
        {
            s++;
        }
        else if (p == 'h')
        {
            h += s;
        }
        else if (p == 'y')
        {
            y += h;
        }
    }
    cout << y << endl;
    return 0;
}